package com.swak.frame.ratelimit.event;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.swak.frame.ump.EventInfo;
import com.swak.frame.ump.adapter.AlarmEventAdapter;

@Component
public class RateLimitAlarmEvent implements RateAlarmEvent {

    @Autowired
    private AlarmEventAdapter alarmEventAdapter;

    @Override
    public void event(RateLimitEventInfo event) {
        EventInfo.Builder builder = new EventInfo.Builder();
        builder.info("[{}] frequent access triggers current limiting!, qps:{}").bizTag("ratelimit")
            .args(new Object[] {event.getResource(), event.getRate()});
        alarmEventAdapter.event(builder.build());
    }
}
